home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / s / replacemergecodes.pprx < prev    next >
Text File  |  1993-02-15  |  2KB  |  97 lines

  1. /*
  2. @BReplaceMergeCodes  @P@ICopyright Gold Disk Inc., Jan, 1993
  3.  
  4. This Genie will search a document for merge codes which begin with the following sequence:    ««= (for "«" press alt-9)
  5. and end with : »»  (for "»" press alt-0)
  6. It expects to find between the merge codes a valid arexx command or macro which it will interpret. The merge codes will be replaced with the result of the interpreted command.
  7.  
  8.     Example: if a box contained the following text:
  9.     "Hi there, today is ««=FormatDate("%w, %m %dth, %y")»»"
  10. Then, running the macro would result with the following text being placed in the box:
  11.     "Hi there, today is Wednesday, January 26, 1992"
  12.  
  13. This Genie is very flexible because you may also execute disk resident
  14. macros which query databases, etc..
  15.  
  16. */
  17. if ~show(l, "rexxsupport.library") then
  18.     if ~addlib("rexxsupport.library",0,-30) then
  19.     call exit_msg("Please install the rexxsupport.library in your libs: directory before running this Genie")
  20.  
  21. address command
  22. call SafeEndEdit.rexx()
  23. call ppm_AutoUpdate(0)
  24. call ppm_SetBatchMode(1)
  25.  
  26. call ppm_ShowStatus("Working..")
  27. box = ppm_DocFirstBox()
  28.  
  29. randval = (randu() * time(s))%1
  30.  
  31. do while box ~= 0
  32.  
  33.     if upper(word(ppm_GetBoxInfo(box), 1)) ~= TEXT | ppm_GetBoxUserData(box) = randval then
  34.     do
  35.         box = ppm_DocNextBox(box)
  36.         iterate
  37.     end
  38.  
  39.     oldbox = box
  40.     box = ppm_ArtFirstBox(box)
  41.     boxtext = ppm_GetArticleText(box, 1)
  42.  
  43.     fpos    = pos('««', boxtext)
  44.  
  45.     do while fpos ~= 0
  46.  
  47.         epos    = pos('»»', boxtext, fpos)
  48.         if epos = 0 then leave
  49.  
  50.         if substr(boxtext, fpos + 2, 1) = '=' then
  51.         do
  52.             fieldlen    = epos - fpos + 2
  53.             fieldtext   = strip(substr(boxtext, fpos + 2, fieldlen - 4))
  54.  
  55.             boxtext = delstr(boxtext, fpos, fieldlen)
  56.  
  57.             string = ''
  58.  
  59.             address command
  60.             interpret "string "fieldtext
  61.             address
  62.  
  63.             boxtext = insert(string, boxtext, fpos - 1)
  64.  
  65.         end
  66.  
  67.         fpos = pos('««', boxtext, fpos + 1)
  68.  
  69.     end
  70.  
  71.     call ppm_DeleteContents(box)
  72.     call ppm_TextIntoBox(box, boxtext)
  73.  
  74.     do while box ~= 0
  75.  
  76.         call ppm_SetBoxUserData(box, randval)
  77.         box = ppm_ArtNextBox(box)
  78.     end
  79.  
  80.     box = ppm_DocNextBox(oldbox)
  81.  
  82. end
  83.  
  84.  
  85. exit_msg("Done")
  86.  
  87. exit_msg: procedure 
  88. do
  89.     parse arg message
  90.  
  91.     if message ~= '' then call ppm_Inform(1,message,)
  92.     call ppm_SetBatchMode(0)
  93.     call ppm_ClearStatus()
  94.     call ppm_AutoUpdate(1)
  95.     exit
  96. end
  97.